﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PServiceBus.Transports;

namespace PServiceBus.Services.Web.Runtime {
    public static class TransportHelper {
        static Dictionary<TransportType, Type> _transportTypes = new Dictionary<TransportType, Type>();
        static TransportHelper() {
            PopulateTransportTypes();
        }
        public static Type GetTransportType(int type) {
            var transportType = (TransportType)Enum.Parse(typeof(TransportType), type.ToString());
            return _transportTypes[transportType];
        }

        public static int GetTransportTypeID(Type type) {
            return (int)_transportTypes.FirstOrDefault(t => t.Value == type).Key;
        }

        static void PopulateTransportTypes() {
            _transportTypes[TransportType.Email] = typeof(EmailTransport.EmailTransport);
            _transportTypes[TransportType.Ftp] = typeof(FtpTransport);
            _transportTypes[TransportType.Http] = typeof(HttpTransport);
            _transportTypes[TransportType.MSMQ] = typeof(MSMQTransport);
            _transportTypes[TransportType.RabbitMQ] = typeof(RabbitMQTransport);
            _transportTypes[TransportType.Redis] = typeof(RedisTransport);
            _transportTypes[TransportType.Tcp] = typeof(TcpTransport);
            _transportTypes[TransportType.WebService] = typeof(WebServiceTransport);
            _transportTypes[TransportType.BasicHttp] = typeof(BasicHttpTransport);
            _transportTypes[TransportType.MSSQL] = typeof(PServiceBus.MSSQLTransport.MSSQLTransport);
        }
    }
}
